﻿#ifndef PLAYER_H
#define PLAYER_H


#include "GameDefine.h"


#include "../_Global/GlobalClass.h"
#include "../_Global/Socket/Common.h"
//#include "_Global/UIGlobal.h"


#include <QObject>



///////////////////////////////////////////////////////////////////

class PlayerInfo: public QObject
{
    Q_OBJECT
    Q_PROPERTY(qint32 socketID READ getSocketID)
    Q_PROPERTY(qint32 index READ getIndex)
    Q_PROPERTY(quint32 userGameID READ getUserGameID)

    Q_PROPERTY(QString nickname READ getNickname)
    Q_PROPERTY(qint32 score READ getScore)
    Q_PROPERTY(qint16 sex READ getSex)
    Q_PROPERTY(qint32 serverID READ getServerID)
    Q_PROPERTY(QVariant extraData READ getExtraData)

    Q_PROPERTY(bool isGroupMaster READ isGroupMaster)
    Q_PROPERTY(qint16 clientGroupStatus READ getClientGroupStatus)

public:
    explicit PlayerInfo(QObject *parent = nullptr): QObject(parent)
    {
        clear();
    }

    virtual ~PlayerInfo()
    {
        qDebug() << "PlayerInfo Destroy:" << m_strNickname << m_unUserGameID;
    }

    void clear()
    {
        this->m_nSocketID = -1;
        this->m_nIndex = -1;
        this->m_unUserGameID = 0;

        this->m_strNickname = "";
        this->m_nScore = 0;
        this->m_nServerID = -1;
        this->m_nSex = -1;
        this->m_vExtraData.clear();

        this->m_bIsGroupMaster = false;
        this->m_ClientGroupStatus = _ClientGroupStatus::GroupStatus_Nothing;
    }


    PlayerInfo* operator =(PlayerInfo* v)
    {
        this->m_nSocketID = v->m_nSocketID;
        this->m_nIndex = v->m_nIndex;
        this->m_unUserGameID = v->m_unUserGameID;

        this->m_strNickname = v->m_strNickname;
        this->m_nScore = v->m_nScore;
        this->m_nServerID = v->m_nServerID;
        this->m_nSex = v->m_nSex;
        this->m_vExtraData = v->m_vExtraData;

        this->m_bIsGroupMaster = v->m_bIsGroupMaster;
        this->m_ClientGroupStatus = v->m_ClientGroupStatus;

        return this;
    }


    QString getNickname() const
    {
        return m_strNickname;
    }
    qint16 getSex() const
    {
        return m_nSex;
    }
    qint32 getServerID() const
    {
        return m_nServerID;
    }
    QVariant getExtraData() const
    {
        return m_vExtraData;
    }
    qint32 getScore() const
    {
        return m_nScore;
    }

    qint32 getSocketID() const
    {
        return m_nSocketID;
    }

    qint32 getIndex() const
    {
        return m_nIndex;
    }

    quint32 getUserGameID() const
    {
        return m_unUserGameID;
    }

    bool isGroupMaster() const
    {
        return m_bIsGroupMaster;
    }

    qint16 getClientGroupStatus() const
    {
        return m_ClientGroupStatus;
    }

public:
    qint32      m_nSocketID;
    qint32      m_nIndex;                   //座位号(房间内的唯一ID,0~MaxClient)，并不是游戏座位号
    quint32     m_unUserGameID;                   //座位号(房间内的唯一ID,0~MaxClient)，并不是游戏座位号

    QString     m_strNickname;              //昵称
    qint16      m_nSex;
    qint32      m_nServerID;
    qint32      m_nScore;
    QVariant    m_vExtraData;

    bool        m_bIsGroupMaster;
    _ClientGroupStatus      m_ClientGroupStatus;
};

//玩家
class _Player : public QObject
{
    Q_OBJECT
    Q_ENUMS(JiaoSe)

    Q_PROPERTY(QObject* playerInfo READ getPlayerInfo)    //玩家信息


public:

    //玩家类型
    enum JiaoSe {
        JiaoSe_Null = 0,    //没有玩家
        JiaoSe_Self = 1,    //玩家
        JiaoSe_Others = 2,  //联机玩家
        JiaoSe_AI = 3,      //电脑
        JiaoSe_Server = 4,  //服务器
        JiaoSe_Watcher = 5,  //观察者
        //JiaoSe_Auto = 6     //玩家托管
    };


signals:

    void s_Critical(QString str);


public:
    explicit _Player(QObject *parent = nullptr);
    virtual ~_Player();


public:
    //初始化
    virtual void init();



public:
    //property
    QObject* getPlayerInfo()
    {
        return &m_PlayerInfo;
    }



//游戏外部设置:
public:
    PlayerInfo  m_PlayerInfo;

    JiaoSe      m_eJiaoSe;              //0是AI,1是自己,2是其他玩家
    qint32      m_nDuiWu;               //队伍(-1为无队伍,自己获胜即可)

//游戏中使用数据:
public:
    bool        m_bTuoGuan;           //玩家是否托管



protected:

private:

};

Q_DECLARE_METATYPE(_Player*)

#endif // PLAYER_H
